package com.ucar.umock.client.exector.support;

import com.ucar.umock.client.dto.UMockMethodRuntimeInfoDTO;
import com.ucar.umock.client.util.UMockTypeUtil;
import com.ucar.umock.client.config.UMockMethodConfigBean;
import com.ucar.umock.client.enums.EnumMockExectorType;
import org.springframework.stereotype.Component;

/**
 * @ClassName UMockValueFixedSimpleHandle
 * @Description TODO
 * @Author zhanbs baoshan.zhan@ucarinc.com
 * @Date 2020/4/3 16:11
 * @Version 1.0
 **/
@Component
public class UMockValueFixedSimpleExector extends UMockValueBaseExector {
    public Object exec(UMockMethodConfigBean config, UMockMethodRuntimeInfoDTO methodRuntimeDTO) {
        String value=config.getFixedValue();
        Class retuenClass=methodRuntimeDTO.getReturnClass();
        if(UMockTypeUtil.isBoolean(retuenClass)){
            return Boolean.parseBoolean(defaultString(value,"false"));
        }else if(UMockTypeUtil.isInt(retuenClass)){
            return Integer.parseInt(defaultString(value,"0"));
        }else if(UMockTypeUtil.isByte(retuenClass)){
            return Byte.parseByte(defaultString(value,"0"));
        }else if(UMockTypeUtil.isShort(retuenClass)){
            return Short.parseShort(defaultString(value,"0"));
        }else if(UMockTypeUtil.isLong(retuenClass)){
            return Long.parseLong(defaultString(value,"0"));
        }else if(UMockTypeUtil.isCharacter(retuenClass)){
            value=defaultString(value,"A");
            return value.charAt(0);
        }else if(UMockTypeUtil.isFloat(retuenClass)){
            return Float.parseFloat(defaultString(value,"0.0"));
        }else if(UMockTypeUtil.isDouble(retuenClass)){
            return Double.parseDouble(defaultString(value,"0.0"));
        }else {
            return value;
        }

    }

    public EnumMockExectorType getType() {
        return EnumMockExectorType.FIXED_SIMPLE_VALUE;
    }
}
